//1535.找出数组游戏的赢家
//https://leetcode.cn/problems/find-the-winner-of-an-array-game
class Solution {
public:
    int getWinner(vector<int>& arr, int k) {
        int n = arr.size();
        int cur = 0;
        int cnt = 0;
        //线性遍历查找 出现k次一定是连续出现的
        for (int i = 1; i < n && cnt < k; ++i)
        {
            if (arr[cur] > arr[i]) ++cnt;
            else
            {
                cur = i;
                cnt = 1;
            }
        }

        return arr[cur];
    }
};